/**
 * 功能描述 导航
 */

define(function (require, exports, module) {
	var Component = require("subnav");
	var aw = require("ajaxwrapper");
	var user = require("store").get("user");
	var signupregisterSvc = require("../store/signupregisterSvc");
	
    var instance = {
        initComponent: function (params, widget) {
            var component = new Component({
            	parentNode:".J-subnav",
				model : {
					title:"报名登记",
					items : [{
						id:"servicePoint",
						type:"buttongroup",
						tip:"服务点",
						keyField :"pkServicePoint",
						valueField :"name",
						params: function(){
							return{
								fetchProperties:"pkServicePoint,name"
							}
						},
						items:user.privateServicePoints,
						handler:function(key,element){
							widget.get("grid").refresh();
						}
					},{
						id : "destination",
						type:"buttongroup",
						url:"api/destination/query",
						all:{
							show:true,
							first:true
						},
						tip:"目的地",
						keyField:"pkDestination",
						params:function(){
							return{
								fetchProperties:"pkDestination,name",
							}
						},
						valueField:"name",
						handler:function(){
							widget.get("grid").refresh();
						}
					},{
							id : "payFul",
							tip:"收费状态",
							type:"buttongroup",
							items:[{
								key:"All",
								value:"全部"
							},{
								key:"Charge",
								value:"收费中"
							},{
								key:"ChargeComplete",
								value:"收费完成"
							},{
								key:"Review",
								value:"已复核"
							},{
								key:"Adjustment",
								value:"调整"
							},{
								key:"AdjustmentReview",
								value:"调整复核"
							}],
							handler:function(key,element){
								widget.get("grid").refresh();
							}
						},{
						id : "travelDate",
						type:"daterange",
						ranges : {
					        "本年": [moment().startOf("year"), moment().endOf("days")]
						},
						tip:"报名开始时间",
						handler : function(time){
							 widget.get("grid").refresh();
						}
					},{
						id : "save",
						type : "button",
						text : "保存",
						show : false,
						handler : function(e){
							var griddata = widget.get("editgrid").getData();
							var applyData = widget.get("applyGrid").getData();
							var signUpRoomTypeCountArr = [];
							var signUpRoomTypeCount = [];
							for ( var i in griddata) {
								signUpRoomTypeCount = {
									roomType : griddata[i].roomType,
									roomCount : griddata[i].roomCount,
								}
								signUpRoomTypeCountArr.push(signUpRoomTypeCount);
							}
							var data ={
									signUpRoomTypeCounts:signUpRoomTypeCountArr,
									pkPlanItemGroup:applyData[0].planItemGroup.pkPlanItemGroup,
									version:applyData[0].planItemGroup.version
							}
							
							data = aw.customParam(data);
							
							aw.saveOrUpdate("api/planitemgroup/saveroomtype",data,function(data){
				    			widget.hide([".J-form", ".J-applygrid",".J-detailgrid",".J-editgrid"]).show([".J-grid"]);
								widget.get("subnav").hide(["save", "cancel"]).show(["travelDate", "destination", "servicePoint","payFul"]);
								widget.get("grid").refresh();
							});
						}
					},{
						id : "cancel",
						type : "button",
						text : "返回",
						show : false,
						handler : function(){
							widget.hide([".J-form", ".J-applygrid", ".J-detailgrid",".J-editgrid"]).show(".J-grid");
							widget.get("subnav").hide(["save", "cancel"]).show(["travelDate", "destination", "servicePoint","payFul"]);
							widget.get("grid").refresh();
						}
					},{
						id : "applyCancel",
						type : "button",
						text : "返回",
						show : false,
						handler : function(){
							widget.show([".J-form", ".J-applygrid"]).hide(".J-applyform");
							widget.get("subnav").show(["cancel"]).hide(["travelDate", "destination", "servicePoint","applyCancel","payFul"]);
							widget.get("applyForm").reset();
						}
					}]
				}
            });
            widget.set("subnav", component);
        }
    };
    module.exports = instance;
});
